/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javalens.featurecalculators;

import javalens.astronomy.Event;
import javalens.astronomy.LightCurve;
import javalens.rwrapper.REngineWrapper;
import javalens.*;
import javalens.featurecalculators.FeatureCalculator;
import javalens.util.CalculationException;

/**
 *
 * @author vermaak
 */
public class SingleLensFitFeatureCalculator implements FeatureCalculator {
    private Event fitResultEvent;
    
    public String[] getHeaders() {
        return new String[]{"logSingleLensChisq", "fitB", "fitF", "fitM0", "fitTe", "fitTm"};
    }

    public double[] getValues(LightCurve curve) throws CalculationException {
        REngineWrapper w = REngineWrapper.getREngineWrapper();
        double[] chisq = new double[1];
        fitResultEvent = w.fitSingleLensCurve(curve.getDays(), curve.getMags(), curve.getErrors(), chisq);
        if (fitResultEvent==null) {
            throw new CalculationException("Single lens fit failed.");
        }
        return new double[]{
            Math.log10(chisq[0]),
            fitResultEvent.getB(), 
            fitResultEvent.getF(),
            fitResultEvent.getM0(),
            fitResultEvent.getTe(),fitResultEvent.getTm()
        };
    }

    public Event getFitResultEvent() {
        return fitResultEvent;
    }

}
